const BASEURL = 'https://gmall-prod.atguigu.cn';
const request = (params)=>{
  return new Promise((resolve,reject)=>{
    wx.showLoading({
      title:'正在读取',
    })
    let header = {
      "content-type":"application/json"
    }
    let token = wx.getStorageSync('token');
    // console.log(111);
    token && (header.token = token)
    //执行异步任务，发请求
    wx.request({
      url:BASEURL +params.url,
      data:params.data || {},
      method:params.method|| 'GET',
      header,
      success:(res)=>{
        // console.log(res.data);
        //修改Promise状态为成功的状态
        resolve(res.data);
      },
      fail:(error)=>{
        reject(error);
      },
      complete:()=>{
        //关闭正在读取的状态
        wx.hideLoading();
      }
    })
  })
}
export default request;